<?php

namespace App\Services\Goods;

use App\Models\Goods\Brand;
use App\Services\BaseServices;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

class BrandServices extends BaseServices
{
    /**
     * 获取品牌
     *
     * @param  int  $id
     *
     * @return Brand|Collection|Model|null
     */
    public function getBrand(int $id)
    {
        return Brand::query()->find($id);
    }

    /**
     * 获取品牌列表
     *
     * @param  int  $page
     * @param  int  $limit
     * @param $sort
     * @param $order
     * @param $columns
     *
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
     */
    public function getBrandList(int $page, int $limit, $sort, $order, $columns = ['*'])
    {
        return Brand::query()->where('deleted', 0)
            ->when(!empty($sort) && !empty($order), function (Builder $query) use ($sort, $order) {
                return $query->orderBy($sort, $order);
            })->paginate($limit, $columns, 'page', $page);
        /*if (!empty($sort) && !empty($order)) {
            $query = $query->orderBy($sort, $order);
        }
        return $query->paginate($limit, $columns, 'page', $page);*/
    }
}
